package com.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.mapper.UserMapper;
import com.demo.pojo.User;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class UserServiceImpl1 implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> getList() {
        return userMapper.selectList(null);
    }

    @Override
    public User getById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public Boolean save(User user) {
        return userMapper.insert(user) > 0;
    }

    @Override
    public Boolean updateById(User user) {
        return userMapper.updateById(user) > 0;
    }

    @Override
    public Boolean removeById(Integer id) {
        return userMapper.deleteById(id) > 0;
    }

    @Override
    public IPage<User> getPage(Integer current, Integer size) {
        IPage<User> page = new Page<>(current,size);
        return userMapper.selectPage(page,null);
    }

    @Override
    public List<User> search(String name) {
//        QueryWrapper<User> qw = new QueryWrapper<>();
//        qw.like("name",name);

        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        qw.like(User::getName,name);
        return userMapper.selectList(qw);
    }
}
